<?php
define('ROOT', str_replace("index.php", '', $_SERVER['SCRIPT_FILENAME']));
define('WEBROOT', str_replace("index.php", '', $_SERVER['SCRIPT_NAME']));

require ROOT.'Core/Session.php';
require ROOT.'Core/model.php';
require ROOT.'Core/controller.php';
$params = explode('/', $_GET['p']);
$controller = $params[0];
$action = isset($params[1]) ? $params[1] : 'index';

if (empty($controller)){
	require "Views/index.php";
}
else {
	require 'Controllers/'.$controller.'.php';
	$controller = new $controller();
	if (method_exists($controller, $action)){
		call_user_func_array(array($controller, $action), array_slice($params, 2));
	}
	else{
		echo 'Erreur404';
	}
}
?>